package com.zat.mes.andrmes.dofun.qualitytest.adapter

import android.view.View
import android.widget.TextView
import androidx.core.content.ContextCompat
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.zat.mes.andrmes.R
import com.zat.mes.andrmes.data.QcRecordBean

/**
 * 质检处理activity
 */
class QcRecordOnsiteAdapter(layoutResId: Int,type:Int) :
    BaseQuickAdapter<QcRecordBean, BaseViewHolder>(layoutResId) {

    private var type = type
    override fun convert(helper: BaseViewHolder, item: QcRecordBean) {


        helper.setText(R.id.tvProcNameQualityPlanItem, item?.procName)

        helper.setText(R.id.tvDateQualityPlanItem, item?.qcDate)
        val textViewStatus = helper.getView<TextView>(R.id.tvTypeQualityPlanItem)
        val textPlan = helper.getView<TextView>(R.id.tvTypePlan);
        textPlan.visibility = View.VISIBLE
        if (type==0){
            helper.setText(R.id.btnMoreQualityPlanItem,"质检结果->")
        }else{
            helper.setText(R.id.btnMoreQualityPlanItem,"巡检结果->")
        }
        if (item?.flag == true) {
            textPlan.text = context.getString(R.string.plan_inside)
            //计划内
            helper.setText(R.id.tvEmpNameQualityPlanItem, item?.planEmpName)
            if ("3".equals(item?.status)) {
                //未完成
                textViewStatus.text = context.getString(R.string.quality_no)
                textViewStatus.setTextColor(
                    ContextCompat.getColor(
                        context,
                        R.color.text_not_finished
                    )
                )
                textViewStatus.setBackgroundColor(
                    ContextCompat.getColor(
                        context,
                        R.color.text_bg_not_finished
                    )
                )
            } else if ("5".equals(item?.status)) {
                textViewStatus.text = context.getString(R.string.quality_has)
                textViewStatus.setTextColor(
                    ContextCompat.getColor(
                        context,
                        R.color.text_has_finished
                    )
                )
                textViewStatus.setBackgroundColor(
                    ContextCompat.getColor(
                        context,
                        R.color.text_bg_has_finished
                    )
                )
            } else {

            }
        } else {
            //计划外
            textPlan.text = context.getString(R.string.plan_outside)
            helper.setText(R.id.tvEmpNameQualityPlanItem, "")
            helper.setText(R.id.tvDateQualityPlanItem,"")
            if ("3".equals(item?.status)) {
                //未完成
                textViewStatus.text = context.getString(R.string.quality_no)
                textViewStatus.setTextColor(
                    ContextCompat.getColor(
                        context,
                        R.color.text_not_finished
                    )
                )
                textViewStatus.setBackgroundColor(
                    ContextCompat.getColor(
                        context,
                        R.color.text_bg_not_finished
                    )
                )
            } else if ("5".equals(item?.status)) {
                textViewStatus.text = context.getString(R.string.quality_has)
                textViewStatus.setTextColor(
                    ContextCompat.getColor(
                        context,
                        R.color.text_has_finished
                    )
                )
                textViewStatus.setBackgroundColor(
                    ContextCompat.getColor(
                        context,
                        R.color.text_bg_has_finished
                    )
                )
            } else {

            }
        }


    }
}